/**
  ******************************************************************************
  * @file    oled.h
  * @author  AE Team
  * @version 1.0.3
  * @date    2024-05-28
  * @brief   Header for oled.c file.
  *          This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2024 SIYIMicro.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */


 /* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __OLED_H
#define __OLED_H

#ifdef __cplusplus
extern "C"
{
#endif


/******************************************************************************/
/* Include files                                                              */
/******************************************************************************/
#include "stdint.h"
#include "stdlib.h"
#include "sym32l010_hal_gpio.h"
#include "sym32l010_hal_systick.h"
#include "sym32l010_hal_sysctrl.h"
#include "sym32l010_hal_spi.h"

/******************************************************************************/
/* Global type definitions                                                    */
/******************************************************************************/

/******************************************************************************/
/* Global pre-processor symbols/macros ('#define')                            */
/******************************************************************************/
//OLED模式设置
//0:4线串行模式
//1:并行8080模式
#define OLED_MODE                       0
#define SIZE                            16
#define XLevelL                         0x00
#define XLevelH                         0x10
#define Max_Column                      128
#define Max_Row                         64
#define Brightness                      0xFF
#define X_WIDTH                         128
#define Y_WIDTH                         64

#define OLED_CMD                        0                             // 写命令
#define OLED_DATA                       1                             // 写数据


// OLED接口定义

//RES = PA06
#define OLED_RES_PORT_CLK_EN()          HAL_SYSCTRL_GPIOA_CLK_ENABLE()
#define OLED_RES_PORT                   SYM_GPIOA
#define OLED_RES_PIN                    GPIO_PIN_6
#define OLED_RES_CLR()                  PA06_SETLOW()
#define OLED_RES_SET()                  PA06_SETHIGH()

//DC = PA03
#define OLED_DC_PORT_CLK_EN()           HAL_SYSCTRL_GPIOA_CLK_ENABLE()
#define OLED_DC_PORT                    SYM_GPIOA
#define OLED_DC_PIN                     GPIO_PIN_3
#define OLED_DC_CLR()                   PA03_SETLOW()
#define OLED_DC_SET()                   PA03_SETHIGH()

//CS = SPI_NCS(PA02)
#define OLED_CS_PORT_CLK_EN()           HAL_SYSCTRL_GPIOA_CLK_ENABLE()
#define OLED_CS_PORT                    SYM_GPIOA
#define OLED_CS_PIN                     GPIO_PIN_2
#define OLED_CS_AF                      AFx_SPI1NCS_PA02

//D0 = SPI_SCK(PA05)
#define OLED_D0_PORT_CLK_EN()           HAL_SYSCTRL_GPIOA_CLK_ENABLE()
#define OLED_D0_PORT                    SYM_GPIOA
#define OLED_D0_PIN                     GPIO_PIN_5
#define OLED_D0_AF                      AFx_SPI1SCK_PA05

//D1 = SPI_MOSI(PB06)
#define OLED_D1_PORT_CLK_EN()           HAL_SYSCTRL_GPIOB_CLK_ENABLE()
#define OLED_D1_PORT                    SYM_GPIOB
#define OLED_D1_PIN                     GPIO_PIN_6
#define OLED_D1_AF                      AFx_SPI1MOSI_PB06

//定义OLED所用到的SPI
#define OLED_CHIP_SPI_CLK_EN()          HAL_SYSCTRL_SPI1_CLK_ENABLE()
#define OLED_CHIP_SPI                   SYM_SPI1

#define OLED_TIMEOUT_VALUE              1000

/******************************************************************************/
/* Global macro function                                                      */
/******************************************************************************/


/******************************************************************************/
/* Exported variables ('extern', definition in C source)                      */
/******************************************************************************/
extern SPI_HandleTypeDef hspi1;

/******************************************************************************/
/* Global function prototypes ('extern', definition in C source)              */
/******************************************************************************/

//OLED控制用函数
#define OLED_CHIP_ENABLE()              HAL_SPI_SSI_SETLOW(&hspi1)    // SPI CS置低
#define OLED_CHIP_DISABLE()             HAL_SPI_SSI_SETHIGH(&hspi1)   // SPI CS置高

void OLED_WR_Byte(uint8_t dat, uint8_t cmd);
void OLED_Display_On(void);
void OLED_Display_Off(void);
void OLED_Init(void);
void OLED_Clear(void);
void OLED_DrawPoint(uint8_t x, uint8_t y, uint8_t t);
void OLED_Fill(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t dot);
void OLED_ShowChar(uint8_t x, uint8_t y, char chr);
void OLED_ShowNum(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size);
void OLED_ShowString(uint8_t x, uint8_t y, char *p);
void OLED_Set_Pos(uint8_t x, uint8_t y);
void OLED_ShowCHinese(uint8_t x, uint8_t y, uint8_t no);
void OLED_DrawBMP(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t BMP[]);


#ifdef __cplusplus
}
#endif

#endif /* __OLED_H */


/************************ (C) COPYRIGHT SIYIMicro *****END OF FILE*************/
